class NamedBeanManager {
  private readonly _reactiveMap: Map<string | number, Object>;
  // eslint-disable-next-line no-use-before-define
  private static _instance: NamedBeanManager;
  // eslint-disable-next-line no-useless-constructor
  private constructor () {
    this._reactiveMap = new Map<string | number, Object>();
  }

  static get instance (): NamedBeanManager {
    if (!this._instance) {
      this._instance = new NamedBeanManager();
    }
    return this._instance;
  }

  public get reactiveMap () {
    return this._reactiveMap;
  }
}

export const namedBean = <T>(source: T, name: string | number): T => {
  NamedBeanManager.instance.reactiveMap.set(name, source);
  return source;
};

export const getNamedBean = <T>(name: string | number): T | undefined => {
  return NamedBeanManager.instance.reactiveMap.get(name) as T | undefined;
};
export const clearBean = () => {
  NamedBeanManager.instance.reactiveMap.clear();
};
